package com.woniu.smart.service.impl;

import com.github.pagehelper.PageHelper;
import com.woniu.smart.dto.WarningDTO;
import com.woniu.smart.entity.Warning;
import com.woniu.smart.mapper.OperationMapper;
import com.woniu.smart.mapper.WarningMapper;
import com.woniu.smart.service.WarningService;
import com.woniu.smart.vo.WarningVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @program: smart
 * @description:
 * @author: qqq
 * @create: 2022-10-23 02:36
 **/
@Service
public class WarningServiceImpl implements WarningService {
    @Autowired
    private WarningMapper warningMapper;
    @Autowired
    private OperationMapper operationMapper;
    @Override
    public List<WarningVO> selectAll(WarningDTO warningDTO) {
        PageHelper.startPage(warningDTO.getCurrentPage(),warningDTO.getPageSize());
        return warningMapper.selectAll(warningDTO);
    }

    @Override
    public int deleteByPrimaryKey(Long id) {
        return warningMapper.deleteByPrimaryKey(id);
    }

    @Override
    public int insert(Warning record) {
        return warningMapper.insert(record);
    }

    @Override
    public int insertSelective(Warning record) {
        return warningMapper.insertSelective(record);
    }

    @Override
    public WarningVO selectByPrimaryKey(Long id) {
        return warningMapper.selectByPrimaryKey(id);
    }

    @Override
    public int updateByPrimaryKeySelective(WarningVO record) {
        return warningMapper.updateByPrimaryKeySelective(record);
    }
    @Override
    @Transactional
    public int requestDesignating(WarningVO record) {
        record.setOperationContent(record.getWarningName());
        record.setOperationTime(record.getWarningTime());
        record.setOperationStatus(1);
        record.setWarningStatus(2);
        record.setRepairTypeId(1);
        operationMapper.insertSelective(record);
        return warningMapper.updateByPrimaryKeySelective(record);
    }

    @Override
    public int updateByPrimaryKey(Warning record) {
        return warningMapper.updateByPrimaryKey(record);
    }
}
